<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="合同名称
" prop="namecontract">
      <el-input v-model="dataForm.namecontract" placeholder="合同名称
"></el-input>
    </el-form-item>
    <el-form-item label="机构名称" prop="oameorganization">
      <el-input v-model="dataForm.oameorganization" placeholder="机构名称"></el-input>
    </el-form-item>
    <el-form-item label="合同类型" prop="typecontract">
      <el-input v-model="dataForm.typecontract" placeholder="合同类型"></el-input>
    </el-form-item>
    <el-form-item label="合同总金额" prop="amount">
      <el-input v-model="dataForm.amount" placeholder="合同总金额"></el-input>
    </el-form-item>
    <el-form-item label="经办人" prop="gestores">
      <el-input v-model="dataForm.gestores" placeholder="经办人"></el-input>
    </el-form-item>
    <el-form-item label="审核状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="审核状态"></el-input>
    </el-form-item>
    <el-form-item label="签约日期" prop="datesigning">
      <el-input v-model="dataForm.datesigning" placeholder="签约日期"></el-input>
    </el-form-item>
    <el-form-item label="到期日期" prop="expirydate">
      <el-input v-model="dataForm.expirydate" placeholder="到期日期"></el-input>
    </el-form-item>
    <el-form-item label="购买产品类别" prop="producttype">
      <el-input v-model="dataForm.producttype" placeholder="购买产品类别"></el-input>
    </el-form-item>
    <el-form-item label="服务方式" prop="serviceway">
      <el-input v-model="dataForm.serviceway" placeholder="服务方式"></el-input>
    </el-form-item>
    <el-form-item label="资源范围" prop="sourcerange">
      <el-input v-model="dataForm.sourcerange" placeholder="资源范围"></el-input>
    </el-form-item>
    <el-form-item label="合同性质" prop="contractnature">
      <el-input v-model="dataForm.contractnature" placeholder="合同性质"></el-input>
    </el-form-item>
    <el-form-item label="合同联系人" prop="contractcon">
      <el-input v-model="dataForm.contractcon" placeholder="合同联系人"></el-input>
    </el-form-item>
    <el-form-item label="付款方式" prop="paystyle">
      <el-input v-model="dataForm.paystyle" placeholder="付款方式"></el-input>
    </el-form-item>
    <el-form-item label="负责代理" prop="agent">
      <el-input v-model="dataForm.agent" placeholder="负责代理"></el-input>
    </el-form-item>
    <el-form-item label="博看签字人" prop="singer">
      <el-input v-model="dataForm.singer" placeholder="博看签字人"></el-input>
    </el-form-item>
    <el-form-item label="博看盖章签字" prop="sign">
      <el-input v-model="dataForm.sign" placeholder="博看盖章签字"></el-input>
    </el-form-item>
    <el-form-item label="机构签字人" prop="mechanismpeople">
      <el-input v-model="dataForm.mechanismpeople" placeholder="机构签字人"></el-input>
    </el-form-item>
    <el-form-item label="机构盖章签字" prop="seal">
      <el-input v-model="dataForm.seal" placeholder="机构盖章签字"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remarks">
      <el-input v-model="dataForm.remarks" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item label="合同扫描件" prop="scanfile">
      <el-input v-model="dataForm.scanfile" placeholder="合同扫描件"></el-input>
    </el-form-item>
    <el-form-item label="审核状态" prop="examine">
      <el-input v-model="dataForm.examine" placeholder="审核状态"></el-input>
    </el-form-item>
    <el-form-item label="合同到期提醒" prop="expirationreminder">
      <el-input v-model="dataForm.expirationreminder" placeholder="合同到期提醒"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          namecontract: '',
          oameorganization: '',
          typecontract: '',
          amount: '',
          gestores: '',
          status: '',
          datesigning: '',
          expirydate: '',
          producttype: '',
          serviceway: '',
          sourcerange: '',
          contractnature: '',
          contractcon: '',
          paystyle: '',
          agent: '',
          singer: '',
          sign: '',
          mechanismpeople: '',
          seal: '',
          remarks: '',
          scanfile: '',
          examine: '',
          expirationreminder: ''
        },
        dataRule: {
          namecontract: [
            { required: true, message: '合同名称
不能为空', trigger: 'blur' }
          ],
          oameorganization: [
            { required: true, message: '机构名称不能为空', trigger: 'blur' }
          ],
          typecontract: [
            { required: true, message: '合同类型不能为空', trigger: 'blur' }
          ],
          amount: [
            { required: true, message: '合同总金额不能为空', trigger: 'blur' }
          ],
          gestores: [
            { required: true, message: '经办人不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '审核状态不能为空', trigger: 'blur' }
          ],
          datesigning: [
            { required: true, message: '签约日期不能为空', trigger: 'blur' }
          ],
          expirydate: [
            { required: true, message: '到期日期不能为空', trigger: 'blur' }
          ],
          producttype: [
            { required: true, message: '购买产品类别不能为空', trigger: 'blur' }
          ],
          serviceway: [
            { required: true, message: '服务方式不能为空', trigger: 'blur' }
          ],
          sourcerange: [
            { required: true, message: '资源范围不能为空', trigger: 'blur' }
          ],
          contractnature: [
            { required: true, message: '合同性质不能为空', trigger: 'blur' }
          ],
          contractcon: [
            { required: true, message: '合同联系人不能为空', trigger: 'blur' }
          ],
          paystyle: [
            { required: true, message: '付款方式不能为空', trigger: 'blur' }
          ],
          agent: [
            { required: true, message: '负责代理不能为空', trigger: 'blur' }
          ],
          singer: [
            { required: true, message: '博看签字人不能为空', trigger: 'blur' }
          ],
          sign: [
            { required: true, message: '博看盖章签字不能为空', trigger: 'blur' }
          ],
          mechanismpeople: [
            { required: true, message: '机构签字人不能为空', trigger: 'blur' }
          ],
          seal: [
            { required: true, message: '机构盖章签字不能为空', trigger: 'blur' }
          ],
          remarks: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          scanfile: [
            { required: true, message: '合同扫描件不能为空', trigger: 'blur' }
          ],
          examine: [
            { required: true, message: '审核状态不能为空', trigger: 'blur' }
          ],
          expirationreminder: [
            { required: true, message: '合同到期提醒不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/com.emp/contract/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.namecontract = data.contract.namecontract
                this.dataForm.oameorganization = data.contract.oameorganization
                this.dataForm.typecontract = data.contract.typecontract
                this.dataForm.amount = data.contract.amount
                this.dataForm.gestores = data.contract.gestores
                this.dataForm.status = data.contract.status
                this.dataForm.datesigning = data.contract.datesigning
                this.dataForm.expirydate = data.contract.expirydate
                this.dataForm.producttype = data.contract.producttype
                this.dataForm.serviceway = data.contract.serviceway
                this.dataForm.sourcerange = data.contract.sourcerange
                this.dataForm.contractnature = data.contract.contractnature
                this.dataForm.contractcon = data.contract.contractcon
                this.dataForm.paystyle = data.contract.paystyle
                this.dataForm.agent = data.contract.agent
                this.dataForm.singer = data.contract.singer
                this.dataForm.sign = data.contract.sign
                this.dataForm.mechanismpeople = data.contract.mechanismpeople
                this.dataForm.seal = data.contract.seal
                this.dataForm.remarks = data.contract.remarks
                this.dataForm.scanfile = data.contract.scanfile
                this.dataForm.examine = data.contract.examine
                this.dataForm.expirationreminder = data.contract.expirationreminder
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/com.emp/contract/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'namecontract': this.dataForm.namecontract,
                'oameorganization': this.dataForm.oameorganization,
                'typecontract': this.dataForm.typecontract,
                'amount': this.dataForm.amount,
                'gestores': this.dataForm.gestores,
                'status': this.dataForm.status,
                'datesigning': this.dataForm.datesigning,
                'expirydate': this.dataForm.expirydate,
                'producttype': this.dataForm.producttype,
                'serviceway': this.dataForm.serviceway,
                'sourcerange': this.dataForm.sourcerange,
                'contractnature': this.dataForm.contractnature,
                'contractcon': this.dataForm.contractcon,
                'paystyle': this.dataForm.paystyle,
                'agent': this.dataForm.agent,
                'singer': this.dataForm.singer,
                'sign': this.dataForm.sign,
                'mechanismpeople': this.dataForm.mechanismpeople,
                'seal': this.dataForm.seal,
                'remarks': this.dataForm.remarks,
                'scanfile': this.dataForm.scanfile,
                'examine': this.dataForm.examine,
                'expirationreminder': this.dataForm.expirationreminder
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
